package com.example.sys.ai.dto;

import com.alibaba.fastjson.JSONObject;
import com.example.core.utils.StringUtils;
import lombok.Data;

import java.io.Serializable;

@Data
public class Face implements Serializable {

    public static final String RESULT = "result";

    public static final String ERROR_MSG = "error_msg";

    public static final String SUCCESS = "SUCCESS";

    public static final String SCORE = "score";

    private float score;

    private boolean validity;

    /***
     * 人员识别校验
     * @param json
     * @return
     */
    public static Face toFace(String json){
        Face face = new Face();
        if (StringUtils.isNotEmpty(json)){
            JSONObject jsonObject = JSONObject.parseObject(json);
            if (jsonObject.containsKey(ERROR_MSG) && jsonObject.getString(ERROR_MSG).equalsIgnoreCase(SUCCESS)){
                if (jsonObject.containsKey(RESULT)) {
                    Float score = jsonObject.getJSONObject(RESULT).getFloat(SCORE);
                    face.setScore(score);
                    face.setValidity(true);
                }
            }
        }
        return face;
    }
}
